package cloud.simple.service.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cloud.simple.service.UserService;
import cloud.simple.service.conf.ConfigProperties;
import cloud.simple.service.model.User;

@RestController
@EnableConfigurationProperties(ConfigProperties.class)
@ConfigurationProperties
@RefreshScope //使用后，使用refresh请求能在线更新配置, 否则只能使用 restart更新，但慢
public class UserController {

    @Autowired
    UserService      userService;

    @Autowired
    ConfigProperties config;

    @Value("${my.message}")
    private String   test;

    @RequestMapping(value = "/user", method = RequestMethod.GET)
    public List<User> readUserInfo() {
        List<User> ls = userService.searchAll();
        return ls;
    }

    @RequestMapping(value = "/config", method = RequestMethod.GET)
    public Object config() {
        Object obj = config.getMessage();
        return obj + " " + test;
    }
}
